class FactoriesController < ApplicationController
  #before_filter :login_required, :except => [:index]
  #To skip this in a subclassed controller
  #skip_before_filter :login_required
  layout "main"

# GET /factories
  # GET /factories.xml
  def index
    @factories = Factory.find(:all)

    respond_to do |format|
      format.html # index.html.erb
      format.xml  { render :xml => @factories }
    end
  end

  # GET /factories/1
  # GET /factories/1.xml
  def show
    @body_id = "leechdoms"
    @factory = Factory.find(params[:id])

    respond_to do |format|
      format.html # show.html.erb
      format.xml  { render :xml => @factory }
    end
  end

  # GET /factories/new
  # GET /factories/new.xml
  def new
    @factory = Factory.new

    respond_to do |format|
      format.html # new.html.erb
      format.xml  { render :xml => @factory }
    end
  end

  # GET /factories/1/edit
  def edit
    @factory = Factory.find(params[:id])
  end

  # POST /factories
  # POST /factories.xml
  def create
    @factory = Factory.new(params[:factory])

    respond_to do |format|
      if @factory.save
        flash[:notice] = 'Factory was successfully created.'
        format.html { redirect_to(@factory) }
        format.xml  { render :xml => @factory, :status => :created, :location => @factory }
      else
        format.html { render :action => "new" }
        format.xml  { render :xml => @factory.errors, :status => :unprocessable_entity }
      end
    end
  end

  # PUT /factories/1
  # PUT /factories/1.xml
  def update
    @factory = Factory.find(params[:id])

    respond_to do |format|
      if @factory.update_attributes(params[:factory])
        flash[:notice] = 'Factory was successfully updated.'
        format.html { redirect_to(@factory) }
        format.xml  { head :ok }
      else
        format.html { render :action => "edit" }
        format.xml  { render :xml => @factory.errors, :status => :unprocessable_entity }
      end
    end
  end

  # DELETE /factories/1
  # DELETE /factories/1.xml
  def destroy
    @factory = Factory.find(params[:id])
    @factory.destroy

    respond_to do |format|
      format.html { redirect_to(factories_url) }
      format.xml  { head :ok }
    end
  end
  
  def list
    @body_id = "leechdoms"
    @factory = Factory.find(params[:id])
    @leechdoms = @factory.leechdoms.paginate  :page => params[:page], :per_page => 10
  end
end
